<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="68px">
			<el-form-item label="技师姓名" prop="technicianName">
				<el-input v-model="queryParams.technicianName" placeholder="请输入技师姓名" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="手机号" prop="technicianTel">
				<el-input v-model="queryParams.technicianTel" placeholder="请输入技师手机号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="在线状态" prop="isOnline">
				<el-select v-model="queryParams.isOnline" placeholder="请选择在线状态" clearable>
					<el-option v-for="dict in dict.type.is_online" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item label="技师身份" prop="technicianIdentity">
				<el-select v-model="queryParams.technicianIdentity" placeholder="请选择技师身份" clearable>
					<el-option v-for="dict in dict.type.technician_identity" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item label="所属商家" prop="merchantId">
				<el-select v-model="queryParams.merchantId" placeholder="请选择">
					<el-option v-for="item in merchantList" :key="item.id" :label="item.merchantName" :value="item.id">
					</el-option>
				</el-select>
				<!-- <el-input v-model="queryParams.merchantId" placeholder="请输入所属商家" clearable
					@keyup.enter.native="handleQuery" /> -->
			</el-form-item>
			<el-form-item label="技师性别" prop="technicianSex">
				<el-select v-model="queryParams.technicianSex" placeholder="请选择技师性别" clearable>
					<el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>

			<el-form-item label="技师来源" prop="technicianSource">
				<el-select v-model="queryParams.technicianSource" placeholder="请选择技师来源" clearable>
					<el-option v-for="dict in dict.type.technician_source" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-plus" size="small" @click="handleAdd"
					v-hasPermi="['technician:technician:add']">新增技师</el-button>
			</el-col>
			<!-- <el-col :span="1.5">
				<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
					v-hasPermi="['technician:technician:edit']">修改</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
					@click="handleDelete" v-hasPermi="['technician:technician:remove']">删除</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
					v-hasPermi="['technician:technician:export']">导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
		</el-row>

		<el-table v-loading="loading" :data="technicianList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="技师ID" align="center" prop="id" />
			<el-table-column label="技师类型" align="center" prop="technicianTypeName" />
			<el-table-column label="技师姓名" align="center" prop="technicianName" />
			<el-table-column label="技师头像" align="center" prop="technicianAvatar" width="100">
				<template slot-scope="scope">
					<image-preview :src="scope.row.technicianAvatar" :width="50" :height="50" />
				</template>
			</el-table-column>
			<el-table-column label="技师手机号" align="center" prop="technicianTel" />
			<el-table-column label="在线状态" align="center" prop="isOnline">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.is_online" :value="scope.row.isOnline" />
				</template>
			</el-table-column>
			<el-table-column label="技师身份" align="center" prop="technicianIdentity">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.technician_identity" :value="scope.row.technicianIdentity" />
				</template>
			</el-table-column>
			<el-table-column label="所属商家" align="center" prop="merchantName" />
			<el-table-column label="所属经纪人" align="center" prop="partnerBrokerName" />
			<el-table-column label="关联用户" align="center" prop="userName" />
			<el-table-column label="技师性别" align="center" prop="technicianSex">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.sys_user_sex" :value="scope.row.technicianSex" />
				</template>
			</el-table-column>
			<el-table-column label="技师身份证" align="center" prop="idCard" />

			<el-table-column label="生活照片" align="center" prop="lifePhoto" width="100">
				<template slot-scope="scope">
					<image-preview :src="scope.row.lifePhoto" :width="50" :height="50" />
				</template>
			</el-table-column>
			<!-- <el-table-column label="所在城市" align="center" prop="serviceCity" /> -->
			<el-table-column label="当前定位" align="center" prop="currentLocation" />
			<el-table-column label="技师来源" align="center" prop="technicianSource">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.technician_source" :value="scope.row.technicianSource" />
				</template>
			</el-table-column>
			<el-table-column label="申请时间" align="center" prop="createTime" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.createTime) }}</span>
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
						v-hasPermi="['technician:technician:edit']">修改</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['technician:technician:remove']">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" />

		<!-- 添加或修改技师管理对话框 -->
		<el-drawer :title="title" :visible.sync="open" width="500px" append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
				<el-form-item label="技师姓名" prop="technicianName">
					<el-input v-model="form.technicianName" placeholder="请输入技师姓名" />
				</el-form-item>
				<el-form-item label="技师头像" prop="technicianAvatar">
					<image-upload v-model="form.technicianAvatar" />
				</el-form-item>
				<el-form-item label="技师手机号" prop="technicianTel">
					<el-input v-model="form.technicianTel" placeholder="请输入技师手机号" />
				</el-form-item>
				<el-form-item label="在线状态" prop="isOnline">
					<el-radio-group v-model="form.isOnline">
						<el-radio v-for="dict in dict.type.is_online" :key="dict.value"
							:label="parseInt(dict.value)">{{dict.label}}</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="技师身份" prop="technicianIdentity">
					<el-radio-group v-model="form.technicianIdentity">
						<el-radio v-for="dict in dict.type.technician_identity" :key="dict.value"
							:label="parseInt(dict.value)">{{dict.label}}</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="所属商家" prop="merchantId">
					<el-input v-model="form.merchantId" placeholder="请输入所属商家" />
				</el-form-item>
				<el-form-item label="关联用户" prop="userId">
					<el-input v-model="form.userId" placeholder="请输入关联用户" />
				</el-form-item>
				<el-form-item label="技师性别" prop="technicianSex">
					<el-radio-group v-model="form.technicianSex">
						<el-radio v-for="dict in dict.type.sys_user_sex" :key="dict.value"
							:label="parseInt(dict.value)">{{dict.label}}</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="技师年龄" prop="technicianAge">
					<el-input v-model="form.technicianAge" placeholder="请输入技师年龄" />
				</el-form-item>
				<el-form-item label="技师密码" prop="technicianPass">
					<el-input v-model="form.technicianPass" placeholder="请输入技师密码" />
				</el-form-item>
				<el-form-item label="技师身份证" prop="idCard">
					<el-radio-group v-model="form.idCard">
						<el-radio v-for="dict in dict.type.technician_identity" :key="dict.value"
							:label="dict.value">{{dict.label}}</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="经度" prop="longitude">
					<el-input v-model="form.longitude" placeholder="请输入经度" />
				</el-form-item>
				<el-form-item label="纬度" prop="latitude">
					<el-input v-model="form.latitude" placeholder="请输入纬度" />
				</el-form-item>
				<el-form-item label="可服务项目" prop="serviceItem">
					<el-input v-model="form.serviceItem" placeholder="请输入可服务项目" />
				</el-form-item>
				<el-form-item label="评分" prop="mark">
					<el-input v-model="form.mark" placeholder="请输入评分" />
				</el-form-item>
				<el-form-item label="用户端展示接单量时间" prop="orderReceivingTime">
					<el-radio-group v-model="form.orderReceivingTime">
						<el-radio v-for="dict in dict.type.order_receiving_time" :key="dict.value"
							:label="parseInt(dict.value)">{{dict.label}}</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="生活照片" prop="lifePhoto">
					<image-upload v-model="form.lifePhoto" />
				</el-form-item>
				<el-form-item label="民族" prop="technicianEthnic">
					<el-input v-model="form.technicianEthnic" placeholder="请输入民族" />
				</el-form-item>
				<el-form-item label="身高" prop="technicianHeight">
					<el-input v-model="form.technicianHeight" placeholder="请输入身高" />
				</el-form-item>
				<el-form-item label="体重" prop="technicianWeight">
					<el-input v-model="form.technicianWeight" placeholder="请输入体重" />
				</el-form-item>
				<el-form-item label="技师简介">
					<editor v-model="form.technicianIntro" :min-height="192" />
				</el-form-item>
				<el-form-item label="白天免费距离" prop="dayFreeTolls">
					<el-input v-model="form.dayFreeTolls" placeholder="请输入白天免费距离" />
				</el-form-item>
				<el-form-item label="晚上免费距离" prop="nightFreeTolls">
					<el-input v-model="form.nightFreeTolls" placeholder="请输入晚上免费距离" />
				</el-form-item>
				<el-form-item label="服务距离" prop="serviceDistance">
					<el-input v-model="form.serviceDistance" placeholder="请输入服务距离" />
				</el-form-item>
				<el-form-item label="分成等级" prop="gradeId">
					<el-input v-model="form.gradeId" placeholder="请输入分成等级" />
				</el-form-item>
				<el-form-item label="所在城市" prop="serviceCity">
					<el-input v-model="form.serviceCity" placeholder="请输入所在城市" />
				</el-form-item>
				<el-form-item label="技师上级邀请码" prop="technicianInvitedCode">
					<el-input v-model="form.technicianInvitedCode" placeholder="请输入技师上级邀请码" />
				</el-form-item>
				<el-form-item label="技师来源" prop="technicianSource">
					<el-radio-group v-model="form.technicianSource">
						<el-radio v-for="dict in dict.type.technician_source" :key="dict.value"
							:label="parseInt(dict.value)">{{dict.label}}</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="常规项目分成比例" prop="splitRate">
					<el-input v-model="form.splitRate" placeholder="请输入常规项目分成比例" />
				</el-form-item>
				<el-form-item label="升级套餐分成比例" prop="upgradeSplitRate">
					<el-input v-model="form.upgradeSplitRate" placeholder="请输入升级套餐分成比例" />
				</el-form-item>
				<el-form-item label="第一次加钟分成比例" prop="bellFirstSplitRate">
					<el-input v-model="form.bellFirstSplitRate" placeholder="请输入第一次加钟分成比例" />
				</el-form-item>
				<el-form-item label="第二次加钟分成比例" prop="bellSecondSplitRate">
					<el-input v-model="form.bellSecondSplitRate" placeholder="请输入第二次加钟分成比例" />
				</el-form-item>
				<el-form-item label="生效开始日期" prop="effectStartTime">
					<el-date-picker clearable v-model="form.effectStartTime" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择生效开始日期">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="生效结束日期" prop="effectEndTime">
					<el-date-picker clearable v-model="form.effectEndTime" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择生效结束日期">
					</el-date-picker>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-drawer>
	</div>
</template>

<script>
	import {
		listTechnician,
		delTechnician,
		addTechnician,
		updateTechnician,
		getTechnician
	} from "@/api/technician/technician";
	import {
		listMerchant
	} from "@/api/merchant/merchant";
	export default {
		name: "Technician",
		dicts: ['technician_identity', 'is_online', 'order_receiving_time', 'sys_user_sex', 'technician_source'],
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 技师管理表格数据
				technicianList: [],
				// 挂靠门店
				merchantList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					technicianType: null,
					technicianName: null,
					technicianTel: null,
					isOnline: null,
					technicianIdentity: null,
					merchantId: null,
					technicianSex: null,
					orderReceivingTime: null,
					technicianWeight: null,
					technicianSource: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {
					technicianName: [{
						required: true,
						message: "技师姓名不能为空",
						trigger: "blur"
					}],
					technicianAvatar: [{
						required: true,
						message: "技师头像不能为空",
						trigger: "blur"
					}],
					technicianTel: [{
						required: true,
						message: "技师手机号不能为空",
						trigger: "blur"
					}],
					isOnline: [{
						required: true,
						message: "在线状态不能为空",
						trigger: "change"
					}],
					idCard: [{
						required: true,
						message: "技师身份证不能为空",
						trigger: "change"
					}],
				}
			};
		},
		created() {
			this.getList();
			this.merchList()
		},
		methods: {
			/** 查询技师管理列表 */
			getList() {
				this.loading = true;
				listTechnician(this.queryParams).then(response => {
					this.technicianList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			/** 查询商家管理列表 */
			merchList() {
				this.loading = true;
				listMerchant({
					pageNum: 1,
					pageSize: 1000,
				}).then(response => {
					this.merchantList = response.rows;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					technicianType: null,
					technicianName: null,
					technicianAvatar: null,
					technicianTel: null,
					isOnline: null,
					technicianIdentity: null,
					merchantId: null,
					userId: null,
					technicianSex: null,
					technicianAge: null,
					openId: null,
					unionid: null,
					technicianPass: null,
					idCard: null,
					technicianYear: null,
					longitude: null,
					latitude: null,
					serviceItem: null,
					mark: null,
					orderReceivingTime: null,
					orderReceiving: null,
					lifePhoto: null,
					technicianEthnic: null,
					technicianHeight: null,
					technicianWeight: null,
					technicianIntro: null,
					dayFreeTolls: null,
					nightFreeTolls: null,
					serviceDistance: null,
					totalRevenue: null,
					onlineTime: null,
					gradeId: null,
					serviceCity: null,
					technicianInvitationCode: null,
					technicianInvitedCode: null,
					technicianSource: null,
					splitRate: null,
					upgradeSplitRate: null,
					bellFirstSplitRate: null,
					bellSecondSplitRate: null,
					effectStartTime: null,
					effectEndTime: null,
					isDelete: null,
					createTime: null,
					updateTime: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.id)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				// this.open = true;
				// this.title = "添加技师管理";
				this.$commonJs.changeView('/technician/technician/addTech')
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const id = row.id || this.ids
				this.$commonJs.changeView('/technician/technician/edit', {
					id: id
				})
				// getTechnician(id).then(response => {
				//   this.form = response.data;
				//   this.open = true;
				//   this.title = "修改技师管理";
				// });
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.form.id != null) {
							updateTechnician(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addTechnician(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const ids = row.id || this.ids;
				this.$modal.confirm('是否确认删除技师管理编号为"' + ids + '"的数据项？').then(function() {
					return delTechnician(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('technician/technician/export', {
					...this.queryParams
				}, `technician_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>